package com.cs.study.homework._0314.queue;


import com.cs.study.homework._0314.list.MyDBLinkedList;

public class MyLinkedQueue<E> {
    private Node front;
    // 队尾
    private Node rear;

    private int size;

    private class Node {
        E value;
        Node next;

        public Node(E value) {
            this.value = value;
        }
    }

    public int size() {
        return size;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean offer(E value) {
        if (isEmpty()) {
            Node node = new Node(value);
            front = rear = node;
            size++;

            return true;
        }
        Node node = new Node(value);
        rear.next = node;
        rear = node;
        size++;
        return true;

    }

    public E pop(){
        if (isEmpty()){
            throw new RuntimeException("queue is empty");
        }
        if (size == 1){
            E value = front.value;
            front = rear = null;
            size--;

            return value;
        }
        E value = front.value;
        front  = front.next;
        size--;
        return value;




    }

}
